<?php

function get_comments($page = 1) {
    global $aldb;
    $perpage = 10;

    $count = $aldb->get_var("SELECT COUNT(id) FROM $aldb->comments");
    $total = ceil($count/$perpage);
    $page = intval($page);
    if (empty($page) || $page < 1) {
        $page = 1;
    } else if ($page > $total) {
        $page = $total;
    }
    $start = ($page -1) * $perpage;
    $posts->page = $page;
    $posts->results = $aldb->get_results("SELECT * FROM $aldb->comments ORDER BY id DESC LIMIT $start, $perpage");
    $posts->pagelink = get_pagelink(Router::get_url() . '/' . ARLICLE_ADMIN . "/comments/comments", $page, $count, $perpage,$total);
    return $posts;
}

?>
